import SwiftUI
import SPGlassKit

public struct GlassAlertExample: GlassExample {
    public static let componentID = "glass-alert"
    @State private var alert: GlassAlert?
    @State private var outcome = "Nothing chosen yet"

    public init() {}

    public var body: some View {
        VStack(spacing: 16) {
            GlassButton("Show information") {
                alert = GlassAlert(title: "Export finished", message: "The sample file was written to Documents.")
            }
            GlassButton("Unsaved changes…") {
                alert = GlassAlert(
                    title: "Save changes?",
                    message: "Your edits to “Budget 2027” will be lost otherwise.",
                    buttons: [
                        GlassAlertButton("Save") { outcome = "Saved" },
                        .destructive("Discard") { outcome = "Discarded" },
                        .cancel { outcome = "Cancelled" },
                    ]
                )
            }
            GlassButton("Delete draft…", systemImage: "trash", role: .destructive) {
                // No cancel button is given: validation adds one because the only action is destructive.
                alert = GlassAlert(
                    title: "Delete this draft?",
                    message: "This cannot be undone.",
                    style: .confirmation,
                    buttons: [.destructive("Delete draft") { outcome = "Deleted" }]
                )
            }
            Text(outcome).font(.callout).foregroundStyle(.secondary)
        }
        .padding()
        .glassAlert($alert)
    }
}

#Preview("GlassAlert") { GlassAlertExample() }
